package com.project.controller;

import com.project.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@Controller
public class TestController {
    @RequestMapping("/")
    public String testThy(HttpServletRequest req, Model model){
        //绑定共享数据
        req.setAttribute("age",20);
        req.setAttribute("name","张三");
        model.addAttribute("phone","1365221211");
        model.addAttribute("user",new UserBean(1,"黄三","1254244522",LocalDate.parse("2001-03-02")));
        req.setAttribute("grade",80);
        req.setAttribute("list", List.of(new UserBean(1,"黄为","1254244522",LocalDate.parse("2001-03-02")),
                new UserBean(2,"陈华","1469545554",LocalDate.parse("2006-03-02")),
                new UserBean(3,"李四","1626654554",LocalDate.parse("2007-03-02")),
                new UserBean(4,"黄虎","7966255225",LocalDate.parse("2005-03-02")),
                new UserBean(5,"小明","3354554455",LocalDate.parse("2011-03-02"))));
         req.setAttribute("totalPage",4);
        //默认是请求转发
        return "/html/index.html";
    }
}
